<?php

namespace Item;

use C\L\WebUserController;

class AprlistController extends WebUserController
{
    protected function init()
    {
        $this->service = $this->s_itemaprlist;

        $this->pubSearchKeys = [
            'cid'
        ];

        $this->hideKeys = [
            'is_delete'
        ];

        $this->timeToDateKeys = [
            'addtime', 'uptime', 'ok_time', 'back_time'
        ];
    }

    protected function befortSearch()
    {
        $page_num = $this->getValue('page_num', false, 'int');
        if (!$page_num) {
            $this->params['page_num'] = 20;
        }
        $this->params['order'] = 'back_time desc';
        $this->params['data']['uid'] = $this->uid;

        return true;
    }

    protected function afterSearch(&$data)
    {
        if ($data['page_curren'] == 1 and !empty($data['list'])) {
            $money_info = $this->s_itemaprlist->moneyBackList($data['list'][0]['cid']);

            if ($money_info) {
                array_unshift($data['list'], $money_info);
            }
        }
        foreach ($data['list'] as &$item) {
            if (!isset($item['type'])) {
                $item['type'] = 2;
            }
            $item['back_time_date'] = ($item['back_time'])?date('Y/m/d H:i:s', $item['back_time']): '';
            $item['ok_time_date'] = ($item['ok_time'])?date('Y/m/d H:i:s', $item['ok_time']): '';
        }

        return true;
    }
}
